//
//  AppDelegate.m
//  李明微博
//
//  Created by 张青花 on 15/12/2.
//  Copyright (c) 2015年 李明. All rights reserved.
//

#import "AppDelegate.h"
#import "LMTabBarController.h"
#import "LMNewFeatureViewController.h"
#import "LMAuthViewController.h"
#import "LMAccountTool.h"
#import "LMRootTool.h"
#import "UIImageView+WebCache.h"

#import <AVFoundation/AVFoundation.h>

@interface AppDelegate ()

@property (nonatomic,strong)AVAudioPlayer *player;

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
   
    UIUserNotificationSettings *setting = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge categories:nil];
    
    [application registerUserNotificationSettings:setting];
    
    AVAudioSession *session = [AVAudioSession sharedInstance];
    
    [session setCategory:AVAudioSessionCategoryPlayback error:nil];
    
    [session setCategory:AVAudioSessionCategorySoloAmbient error:nil];
    
    [session setActive:YES error:nil];
    
    
    //设置window
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    

    if ([LMAccountTool account]) {
        
        [LMRootTool setroot:self.window];
    }
    else
    {
        
        LMAuthViewController *auth = [[LMAuthViewController alloc] init];
        
        self.window.rootViewController = auth;
        
    }
    
    
    self.window.backgroundColor = [UIColor yellowColor];
    
    [self.window makeKeyAndVisible];
    return YES;
}




- (void)applicationWillResignActive:(UIApplication *)application {
    
    NSURL *url = [NSURL URLWithString:@"http://172.30.65.92:9999/yinyueshiting.baidu.com/data2/music/247912224/24791165410800064.mp3"];
    
    AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
    
    [player prepareToPlay];
    
    player.numberOfLoops = -1;
    
    [player play];

    _player = player;

}

- (void)applicationDidEnterBackground:(UIApplication *)application {
 
    UIBackgroundTaskIdentifier ID =[application beginBackgroundTaskWithExpirationHandler:^{
        [application endBackgroundTask:ID];
    }];
    
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    
    [[SDWebImageManager sharedManager] cancelAll];
    [[SDWebImageManager sharedManager].imageCache clearMemory];
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
